#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 2500 + 10;
struct node
{
    int x;
    int y;
}a[N], b[N];
int n, m;
bool cmp(node& s1, node& s2)
{
    return s1.x > s2.x;
}
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].x >> a[i].y;
    }
    for (int i = 1; i <= m; i++)
    {
        cin >> b[i].x >> b[i].y;
    }
    sort(a + 1, a + 1 + n, cmp);
    sort(b + 1, b + 1 + m, cmp);
    int ret = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (b[j].y == 0)
            {
                continue;
            }
            if (a[i].x > b[j].x)
            {
                break;
            }
            if (a[i].y < b[j].x)
            {
                continue;
            }
            ret++;
            b[j].y--;
            break;
        }
    }
    cout << ret << endl;
    return 0;
}